package dungeon;


import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;

/**
 * This class represents a door that can lie between two squares.
 * It can be open or closed.
 * 
 * @invar	| ! this.isInherentlySlippery()
 * 
 * @author Frederik
 *
 */
public class Door extends Obstacle {

	/**
	 * Initialize a new door with given borders.
	 * 
	 * @param firstSquare	The first square that borders this door.
	 * @param secondSquare	The second square that borders this door.
	 * @post	|	! new.isAccessible()
	 */
	public Door() {
		super(false);
		setAccessible(false);
	}
	
	/**
	 * Open this door.
	 * 
	 * @post	| new.isAccessible() == true
	 */
	public void openDoor(){
		setAccessible(true);
		if(getSecondSquare() != null)
			getSecondSquare().resolveSpace();			
	}

	/**
	 * Close this door.
	 * 
	 * @post	| new.isAccessible() == false
	 */
	public void closeDoor(){
		setAccessible(false);
	}

	/**
	 * Return whether this door is accessible.
	 * This means whether the door is open.
	 * 
	 * @return	Whether this door is accessible.
	 */
	@Basic @Raw
	public boolean isAccessible(){
		return this.accessible;
	}

	/**
	 * Set whether this door is accessible.
	 * 
	 * @param accessible	Whether this door is accessible.
	 */
	@Raw
	private void setAccessible(boolean accessible){
		this.accessible = accessible;
	}

	/**
	 * Variable that states whether this door is accessible.
	 */
	private boolean accessible;
	
	/**
	 * Check whether it is a valid square to add to this obstacle.
	 * 
	 * @param 	square
	 * 			The square that is or isn't valid to border this obstacle.
	 * @return	| if (square != null && square != this.getFirstSquare() && !(square instanceof RockSquare))
	 * 			|	then result == true
	 */
	public boolean isValidSquareToAdd(Square square) {
		return (super.isValidSquareToAdd(square) && ! (square instanceof RockSquare));
	}

}
